//
//  HYLMainViewController.swift
//  iOSwechat
//
//  Created by apple on 16/2/26.
//  Copyright © 2016年 apple. All rights reserved.
//

import UIKit

class HYLMainViewController: UITabBarController , HYLMainBarAddDelegate{

    override func viewDidLoad() {
        super.viewDidLoad()
        
        
        let mainTabBarAdd = HYLMainBarAdd()
        setValue(mainTabBarAdd, forKey: "tabBar")
        
        // 设置代理
        mainTabBarAdd.addDelegate = self
        
        addChildViewControllers()

    }
    
    // MARK: - 实现代理方法,响应按钮点击事件
    // 5.实现代理方法
    func mainTabBarAddClick() {
        print("点击了")
    }
    

    // MARK: - 设置tabBarItem 的标题 和 图片
    func addChildViewControllers() {

        let homeVC = HYLHomeViewController()
        self.addChildViewController(homeVC, title: "首页", imageNal: "tabbar_home", imageHighlight: "tabbar_home_highlighted")
        
        
        let message = HYLMeViewContrller()
        self.addChildViewController(message, title: "信息", imageNal: "tabbar_message_center", imageHighlight: "tabbar_message_center_highlighted")
        
        
        addChildViewController(UIViewController())
        
        
        let discover = HYLDiscoverViewController()
        self.addChildViewController(discover, title: "发现", imageNal: "tabbar_discover", imageHighlight: "tabbar_discover_highlighted")
        
        
        let me = HYLMeViewContrller()
        self.addChildViewController(me, title: "我", imageNal: "tabbar_profile", imageHighlight: "tabbar_profile_highlighted")
        
        // 添加到 tabBarVC
    }
    
    
    // MARK: - 添加中间添加按钮
    func addChildViewController(childVC: UIViewController , title : String , imageNal : String , imageHighlight : String) {
        
        self.addChildViewController(UINavigationController(rootViewController: childVC))
        
        childVC.title = title
        childVC.tabBarItem.image = UIImage(named: imageNal)
        // 高亮图片
        let highImage = imageNal + "_highlighted"
        // 设置图片不被渲染
        childVC.tabBarItem.selectedImage = UIImage(named: highImage)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        
        // 设置字体颜色
        childVC.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orangeColor()], forState: UIControlState.Selected)
        
    }
    
    

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    
    

    

}
